package ee.reliability.tool.ui.window;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;

@SuppressWarnings("serial")
public class TxtFileChooser extends JFileChooser  {
	public TxtFileChooser() {
		setAcceptAllFileFilterUsed(false);
		addChoosableFileFilter(new FileFilter() {

			@Override
			public String getDescription() {
				return ".txt Simple text file";
			}

			@Override
			public boolean accept(File f) {
				return f.isDirectory() ? true :
					f.getName().endsWith(".txt");
			}
		});
		setMultiSelectionEnabled(true);
	}

	public ArrayList<Scanner> getSelectedFilesAsScanner() {

		try {
			ArrayList<Scanner> wbList = new ArrayList<>();
			for (File file : getSelectedFiles())
				wbList.add(new Scanner(file));
			return wbList;
		} catch (IOException e) {
			throw new RuntimeException("Can't open file!");
		}
	}
}
